package core

import (
	"github.com/garyburd/redigo/redis"
	"global/libs/structs"
	"fmt"
	"global/constants"
	"encoding/json"
)

// 获取交易所下面单个 symbol
func GetSymbolFromExchange(conn redis.Conn, exchangeName, symbol string) (*structs.Symbol, error) {
	var s structs.Symbol
	key := fmt.Sprintf(constants.SpiderSymbolPairKey, exchangeName)
	val, err := redis.String(conn.Do("HGET", key, symbol))
	if err != nil {
		return nil, err
	}

	if err := json.Unmarshal([]byte(val), &s); err != nil {
		return nil, err
	}

	return &s, nil
}